import { defineConfig } from 'eslint/config';
import globals from 'globals';
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import pluginVue from 'eslint-plugin-vue';
import vueEslintParser from 'vue-eslint-parser';

export default defineConfig([
  {
    ignores: ['dist/**', 'node_modules/**']
  },
  { files: ['**/*.{js,mjs,cjs,ts,vue}'], languageOptions: { globals: globals.browser } },
  { files: ['**/*.{js,mjs,cjs,ts,vue}'], plugins: { js }, extends: ['js/recommended'] },
  tseslint.configs.recommended,
  pluginVue.configs['flat/essential'],
  pluginVue.configs['flat/recommended'],
  {
    files: ['**/*.vue'],
    languageOptions: {
      parser: vueEslintParser,
      parserOptions: {
        ecmaVersion: 'latest',
        sourceType: 'module',
        ecmaFeatures: {
          jsx: true,
        },
      },
    },
  },
  {
    rules: {
      // 代码风格
      quotes: ['warn', 'single'], // 字符串使用单引号
      semi: ['warn', 'always'], // 语句结尾使用分号
      'space-before-function-paren': ['warn', 'never'], // 函数定义时括号前面不加空格
      // 变量声明
      'no-var': 'error', // 禁止使用 var
    },
  },
]);
